Ext.define('FirstMate.controller.MarineWeather',
				{
				extend : 'Ext.app.Controller',
			    store: null,
				views : [ 'FirstMate.view.Forecast'],
				config : {
				    refs: {
				        view: '#forecastView',
				        mainView : '#mainView'
				      }		
				},
				init : function () {
					this.store = Ext.create('FirstMate.store.MarineWeather');
					this.store.on('load',this.onWeatherDataLoaded, this);
				},
				
				onWeatherDataLoaded : function (){
					
					var weather = this.store.getAt(0);
					this.getView().setWeatherForecast(weather);
																																																																													
					if (FirstMate.app.WeatherMarker){
						FirstMate.app.WeatherMarker.setMap(null);
					}
					FirstMate.app.getController('MarineWeather').getView().setActiveWeatherItem();
			    	var position = new google.maps.LatLng(
			    			weather.raw.nearest_area[0].latitude, 
			    			weather.raw.nearest_area[0].longitude
							);
			       
						FirstMate.app.WeatherMarker = new google.maps.Marker({
							position: position,
							icon :'app/resources/icons/wifi.png',
							map: Ext.getCmp('extmap').getMap(),
							visible: true,
							draggable : false
							
						});
						google.maps.event.addListener(FirstMate.app.WeatherMarker, 'click', function() { 
							FirstMate.app.getController('MarineWeather').getView().setActiveWeatherItem();
							FirstMate.app.getController('MarineWeather').getMainView().setActiveItem(2);
						});					
			        

				}

});
